package com.jwd.web

import com.jwd.comm.MapModel
import com.jwd.comm.serverMapPath
import com.jwd.config.AppErrorController
import com.jwd.config.HttpContext
import com.jwd.config.MyWebMvcConfig
import com.jwd.mybatis.CityMapper
import org.apache.log4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.servlet.ModelAndView
import java.util.*
import javax.servlet.http.HttpSession
import java.util.HashMap
import org.springframework.web.bind.annotation.PostMapping


/**
 * Created by udi on 2017.3.4.
 */
@Controller
class Home_Controller {
    companion object {
        private val logger = Logger.getLogger(this::class.java)
    }


    @PostMapping("/logout")
    @ResponseBody
    fun logout(): MapModel {
        return MapModel();
    }

    @PostMapping("/login")
    @ResponseBody
    fun loginPost(account: String, password: String, session: HttpSession): MapModel {
        val map = MapModel()
        if ("123456" != password) {
            map.put("success", false)
            map.put("message", "密码错误")
            return map
        }

        // 设置session
        session.setAttribute(MyWebMvcConfig.SESSION_KEY, account)

        map.put("success", true)
        map.put("message", "登录成功")
        return map
    }
}